---
layout: "default"
title: "String.Index"
description: "Swift documentation for 'String.Index': A character position in a String."
keywords: "String.Index,struct,swift,documentation,getMirror,predecessor,samePositionIn,samePositionIn,samePositionIn,successor"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">struct String.Index</code></div>

<div class="discussion comment">
    <p>A character position in a <code>String</code></p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">BidirectionalIndexType, Comparable, Equatable, ForwardIndexType, Reflectable, _BidirectionalIndexType, _Comparable, _ForwardIndexType, _Incrementable</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_-utf8index-within_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-utf8index-within_-string">init?(<wbr>_:<wbr> UTF8Index, within: String)</a><div class="comment collapse" id="comment-init_-utf8index-within_-string"><div class="p">
    <p>Construct the position in <code>characters</code> that corresponds exactly to
<code>utf8Index</code>. If no such position exists, the result is <code>nil</code>.</p>

<p>Requires: <code>utf8Index</code> is an element of
<code>indices(characters.utf8)</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ utf8Index: UTF8Index, within characters: String)</code>

    </div></div>
</div>
<div class="declaration" id="init_-utf16index-within_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-utf16index-within_-string">init?(<wbr>_:<wbr> UTF16Index, within: String)</a><div class="comment collapse" id="comment-init_-utf16index-within_-string"><div class="p">
    <p>Construct the position in <code>characters</code> that corresponds exactly to
<code>utf16Index</code>. If no such position exists, the result is <code>nil</code>.</p>

<p>Requires: <code>utf16Index</code> is an element of
<code>indices(characters.utf16)</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ utf16Index: UTF16Index, within characters: String)</code>

    </div></div>
</div>
<div class="declaration" id="init_-unicodescalarindex-within_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-unicodescalarindex-within_-string">init?(<wbr>_:<wbr> UnicodeScalarIndex, within: String)</a><div class="comment collapse" id="comment-init_-unicodescalarindex-within_-string"><div class="p">
    <p>Construct the position in <code>characters</code> that corresponds exactly to
<code>unicodeScalarIndex</code>. If no such position exists, the result is <code>nil</code>.</p>

<p>Requires: <code>unicodeScalarIndex</code> is an element of
<code>indices(characters.unicodeScalars)</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ unicodeScalarIndex: UnicodeScalarIndex, within characters: String)</code>

    </div></div>
</div>





<h3>Instance Methods</h3>
<div class="declaration" id="func-getmirror">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-getmirror">func getMirror()</a>
        
<div class="comment collapse" id="comment-func-getmirror"><div class="p">
    <p>Returns a mirror that reflects <code>self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func getMirror() -&gt; MirrorType</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-predecessor">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-predecessor">func predecessor()</a>
        
<div class="comment collapse" id="comment-func-predecessor"><div class="p">
    <p>Returns the previous consecutive value before <code>self</code>.</p>

<p>Requires: the previous value is representable.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func predecessor() -&gt; String.Index</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-samepositionin_-string-utf8view">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-samepositionin_-string-utf8view">func samePositionIn(<wbr>_: String.UTF8View)</a>
        
<div class="comment collapse" id="comment-func-samepositionin_-string-utf8view"><div class="p">
    <p>Return the position in <code>utf8</code> that corresponds exactly
to <code>self</code>.</p>

<p>Requires: <code>self</code> is an element of <code>indices(String(utf8))</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func samePositionIn(utf8: String.UTF8View) -&gt; String.UTF8View.Index</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-samepositionin_-string-utf16view">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-samepositionin_-string-utf16view">func samePositionIn(<wbr>_: String.UTF16View)</a>
        
<div class="comment collapse" id="comment-func-samepositionin_-string-utf16view"><div class="p">
    <p>Return the position in <code>utf16</code> that corresponds exactly
to <code>self</code>.</p>

<p>Requires: <code>self</code> is an element of <code>indices(String(utf16))</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func samePositionIn(utf16: String.UTF16View) -&gt; String.UTF16View.Index</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-samepositionin_-string-unicodescalarview">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-samepositionin_-string-unicodescalarview">func samePositionIn(<wbr>_: String.UnicodeScalarView)</a>
        
<div class="comment collapse" id="comment-func-samepositionin_-string-unicodescalarview"><div class="p">
    <p>Return the position in <code>unicodeScalars</code> that corresponds exactly
to <code>self</code>.</p>

<p>Requires: <code>self</code> is an element of <code>indices(String(unicodeScalars))</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func samePositionIn(unicodeScalars: String.UnicodeScalarView) -&gt; String.UnicodeScalarView.Index</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-successor">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-successor">func successor()</a>
        
<div class="comment collapse" id="comment-func-successor"><div class="p">
    <p>Returns the next consecutive value after <code>self</code>.</p>

<p>Requires: the next value is representable.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func successor() -&gt; String.Index</code>
    
    
</div></div>
</div>


